﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKArchUtils.Utils;

namespace YJKRevitDimensionText.OneKeyPlanDim.Utility
{
	public class LocationComparer : IComparer<SingleLevelDimDataInfo>
	{
		public LocationComparer()
		{
		}

		public LocationComparer(XYZ ptLocation)
		{
			this.m_ptLocation = ptLocation;
		}

		public int Compare(SingleLevelDimDataInfo singleLevelDimDataInfo1, SingleLevelDimDataInfo singleLevelDimDataInfo2)
		{
			try
			{
				if (this.m_ptLocation != null)
				{
					double num = singleLevelDimDataInfo1.PtLocation.DistanceTo(this.m_ptLocation);
					double num2 = singleLevelDimDataInfo2.PtLocation.DistanceTo(this.m_ptLocation);
					if (Geometry.LessThan(num, num2))
					{
						return -1;
					}
					if (!Geometry.LessThan(num, num2))
					{
						return 1;
					}
				}
				if (Geometry.LessThan(singleLevelDimDataInfo1.PtLocation.Y, singleLevelDimDataInfo2.PtLocation.Y))
				{
					return 1;
				}
				if (!Geometry.LessThan(singleLevelDimDataInfo1.PtLocation.Y, singleLevelDimDataInfo2.PtLocation.Y))
				{
					return -1;
				}
				if (Geometry.LessThan(singleLevelDimDataInfo1.PtLocation.X, singleLevelDimDataInfo2.PtLocation.X))
				{
					return 1;
				}
				if (!Geometry.LessThan(singleLevelDimDataInfo1.PtLocation.X, singleLevelDimDataInfo2.PtLocation.X))
				{
					return -1;
				}
			}
			catch
			{
			}
			return 0;
		}

		private XYZ m_ptLocation;
	}
}
